package com.sto.stoapp.activity.administrator.hardware;

import android.content.res.AssetManager;
import android.os.Bundle;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.widget.StoHomeActivity;

import java.io.IOException;
import java.io.InputStream;

/**
 * 软件版本
 * 
 * @author mgf
 * 
 */
public class AdminSoftVersionActivity extends StoHomeActivity {

	private TextView softVersion;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.admin_soft_version);
//		this.setTitleBottom(R.string.software_version,
//				HomeBroadAction.ADMINISTRATOR_BROAD);
		String broadType = getIntent().getStringExtra(
				HomeBroadAction.BROAD_TYPE);
		// 判断是管理员的系统设置还是业务内部的系统设置
		if (broadType != null && !broadType.equals("")) {
			this.setTitleBottom(R.string.software_version, broadType);
		} else {
			this.setTitleBottom(R.string.software_version,
					HomeBroadAction.ADMINISTRATOR_BROAD);
		}
		initText();
	}

	private void initText()
	{
		softVersion = (TextView) findViewById(R.id.version_info);
		AssetManager assetManager = getAssets();
		InputStream is = null;
		try
		{
			is = assetManager.open("update_version.txt");
		}
		catch (Exception e)
		{
			e.printStackTrace();
			ExceptionLog.writeLog("initText", e.getMessage());
		}
		String conHelp = readTextFile(is);
		softVersion.setText(conHelp);
	}

	private String readTextFile(InputStream inputStream)
	{

		byte buf[] = new byte[16*1024];

		int len;
		String s = null;
		try
		{
			len = inputStream.read(buf);
			s = new String(buf, 0, len, "UTF-8");
			s = s.replace("\r\n", "\n");
		}
		catch (IOException e)
		{
			ExceptionLog.writeLog("readTextFile", e.getMessage());
		}
		return s;
	}
	
}
